package com.thread.threadfirst.javaBase.MSB_Volatile;

/**
 * 乱序重排
 */
public class OutOrder {
    public static int a=0,b=0;
    public static int x=0,y=0;

    public static void main(String[] args) throws InterruptedException {
        int i=0;
        for (;;){
            i++;
            x=0;y=0;
            a=0;b=0;
            Thread one=new Thread(()->{
                a=1;
                x=b;
            });

            Thread two=new Thread(()->{
                b=1;
                y=a;
            });
            one.start();two.start();
            one.join();two.join();

            if (x==0 && y==0) {
                System.out.println("第"+i+"次 x= "+x+" y= "+y);
                break;
            }
        }

    }
}
